package org.luo.news.domain.article;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;


import org.luo.common.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Tag(name = "文章管理", description = "文章管理")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping("article")
    @Operation(summary = "添加文章", description = "添加文章")
    public Result article(@RequestBody @Validated Article article){

        return articleService.add(article);
    }

    @GetMapping()
    @Operation(summary = "文章列表", description = "文章列表")

    public Result<Page<Article>> list(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(name = "categoryId", required = false) Integer categoryId,
            @RequestParam(name = "state", required = false) String state
    ){

        return articleService.list(pageNum, pageSize, categoryId, state);
    }

    @GetMapping("/detail")
    @Operation(summary = "文章详情", description = "文章详情")
    public Result detail(@RequestParam("id") Integer id ){
        Result<Article> detail = articleService.detail(id);
        return Result.success(detail);
    }
}
